package com.yjkf.zh.admin.controller;


import com.yjkf.zh.admin.aspect.LogAnnotation;
import com.yjkf.zh.admin.dao.SysDeviceCollectMapper;
import com.yjkf.zh.admin.model.SysDeviceCollect;
import com.yjkf.zh.admin.service.SysDeviceCollectService;
import com.yjkf.zh.core.http.HttpResult;
import com.yjkf.zh.core.page.PageRequest;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("deviceCollect")
public class SysDeviceCollectController {

    @Autowired
    private SysDeviceCollectService sysDeviceCollectService;

    @Autowired
    private SysDeviceCollectMapper sysDeviceCollectMapper;

    @PostMapping(value = "/save")
    @LogAnnotation(content = "添加收藏组变量")
    public HttpResult save(@RequestBody List<SysDeviceCollect> sysDeviceCollectList, HttpServletRequest request){
        Long userId = (Long) request.getSession().getAttribute("userId");
    //    Long collectId=sysDeviceCollectList.get(0).getCollectId();
        return HttpResult.ok(sysDeviceCollectService.savaList(sysDeviceCollectList,userId));

    }

    @GetMapping(value = "/findTableData")
    public HttpResult findTableData(@RequestParam Long collectId, HttpServletRequest request){
        Long userId = (Long) request.getSession().getAttribute("userId");
        return HttpResult.ok((sysDeviceCollectService.findTableData(collectId,userId)));
    }



    @GetMapping(value="/selectCollectName")
    public HttpResult selectColectName(HttpServletRequest request){
        Long userId = (Long) request.getSession().getAttribute("userId");
        return HttpResult.ok(sysDeviceCollectMapper.selectCollectName(userId));
    }
}
